var advertisement = {
    list:function(){
        $.ajax({
            type: "GET",
            url: "../advertisement/list.json",
            cache:false,
            dataType: "json",
            success: function(data){
                if(data.result == 'success'){
                	$.each(data.homeAdList,function(index,obj){
                        $('#ad'+(obj.position)+'FilePath').val(obj.imagePath);
                        $('#ad'+(obj.position)+'Link').val(obj.link);
                        $('#ad'+(obj.position)+'Image').attr("src",config.baseURL+obj.imagePath);
                	});
                }else{
                    $.msgBox.alert({
                        title:'Tips',
                        msg:'System error!Please try again later!',
                        icon:'warning',
                        width:350
                    });
                }
            }
        });
    },
    create:function(position,filePath,link){
    	if(!filePath){
    	   $.msgBox.alert({
                title : 'Tips',
                msg : 'Ad image is null,please select a image file!',
                icon : 'warning',
                width : 400
            });
            return false;
    	}
    	if(!link){
    	   $.msgBox.alert({
    			title : 'Tips',
    			msg : 'Link is null,please input a value!',
    			icon : 'warning',
    			width : 350
    		});
            return false;
    	}
    	$.ajax({
            type: "POST",
            url: "../advertisement/create.json",
            cache:false,
            dataType: "json",
            data : {"imagePath":filePath,"link":link,"position":position},
            success: function(data){
                if(data.result == 'success'){
                   $.msgBox.alert({
                        title : 'Success',
                        msg : 'Set Home Ad Susscess!',
                        icon : 'warning',
                        width : 300
                    });
                }else{
                    $.msgBox.alert({
                        title:'Tips',
                        msg:'System error!Please try again later!',
                        icon:'warning',
                        width:350
                    });
                }
            }
        });
    }
};